package oriol.forns.gutierrez;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;

public class Editor extends Activity {

	private ImageView mostra;
	private ArrayList<Integer> peca;
	private int i = 0;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.editor);
		
		GV.Instancies.edi = (EditorBack) findViewById(R.id.edit);
		
		peca = new ArrayList<Integer>();
		
		mostra = (ImageView) findViewById(R.id.mostra);
		
		mostra.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				GV.Instancies.edi.confirmar(i);
			}
		});
		
		peca.add(R.drawable.blanc);
		peca.add(R.drawable.blau);
		peca.add(R.drawable.groc);
		peca.add(R.drawable.marro);
		peca.add(R.drawable.negre);
		peca.add(R.drawable.taronja);
		peca.add(R.drawable.vermell);
		peca.add(R.drawable.vert);
		peca.add(R.drawable.transpa);
		i = 0;
		
		ImageButton esques = (ImageButton) findViewById(R.id.esquerras);
		esques.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				--i;
				if (i < 0) i = 8;
				mostra.setBackgroundResource(peca.get(i));
				GV.Instancies.edi.moub(0, i);
			}
		});
		
		ImageButton dretas = (ImageButton) findViewById(R.id.dretas);
		dretas.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				++i;
				if (i > 8) i = 0;
				mostra.setBackgroundResource(peca.get(i));
				GV.Instancies.edi.moub(0, i);
			}
		});
		
		ImageButton flechad = (ImageButton) findViewById(R.id.flechad);
		flechad.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				GV.Instancies.edi.moub(1, i);
				GV.Instancies.edi.moue(1, i);
			}
		});
		
		ImageButton flechai = (ImageButton) findViewById(R.id.flechai);
		flechai.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				GV.Instancies.edi.moub(-1, i);
				GV.Instancies.edi.moue(-1, i);
			}
		});
		
		ImageButton flechaa = (ImageButton) findViewById(R.id.flechaa);
		flechaa.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				GV.Instancies.edi.moub(-16, i);
				GV.Instancies.edi.moue(-18, i);
			}
		});
		
		ImageButton flechab = (ImageButton) findViewById(R.id.flechab);
		flechab.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				GV.Instancies.edi.moub(16, i);
				GV.Instancies.edi.moue(18, i);
			}
		});
		
		
		Button prov = (Button) findViewById(R.id.provar);
		prov.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Intent i = new Intent("oriol.forns.gutierrez.PROVA");
				startActivity(i);
			}
		});
		
		
		Button salir = (Button) findViewById(R.id.sortire);
		salir.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});
	}

}
